package com.cec.controller.admin;


import com.cec.service.admin.OldsterService;
import com.cec.dto.OldsterDTO;
import com.cec.result.Result;
import com.cec.vo.OldsterStatusVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 老人信息表 前端控制器
 * </p>
 *
 * @author lt
 * @since 2024-10-25
 */
@Slf4j
@RestController
@Api(tags="老人信息管理")
@RequestMapping("/admin/oldster")
public class OldsterController {
    @Autowired
    private OldsterService oldsterService;

    @GetMapping
    @ApiOperation("分页查询老人信息")
    public Result pageQueryOldster(OldsterDTO oldsterDTO) {
        log.info("pageQueryDTO:{}", oldsterDTO);
        return oldsterService.pageQueryOldster(oldsterDTO);
    }

    @PostMapping
    @ApiOperation("添加老人信息")
    public Result saveOldster(@RequestBody OldsterDTO oldsterDTO){
        log.info("saveOldsterDTO-->{}", oldsterDTO);

        return oldsterService.saveOldster(oldsterDTO);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询老人信息")
    public Result<OldsterDTO> queryOldsterById(@PathVariable Long id) {
        OldsterDTO oldsterDTO = oldsterService.queryOldsterById(id);
        return Result.success(oldsterDTO);
    }

    @PutMapping
    @ApiOperation("修改老人信息")
    public Result updateOldster(@RequestBody OldsterDTO oldsterDTO){
        oldsterService.updateOldster(oldsterDTO);
        return Result.success();
    }

    @DeleteMapping("/logicDel/{id}")
    @ApiOperation("逻辑删除用户信息")
    public Result logicDeleteUserById(@PathVariable Integer id){
        log.info("id-->{}",id);
        return oldsterService.logicDeleteUserById(id);
    }

    @DeleteMapping("/logicBatchDel")
    @ApiOperation("逻辑批量删除用户信息")
    public Result logicBatchDeleteUserByIds(@RequestBody List<Integer> ids){
        log.info("id-->{}",ids);
        return oldsterService.logicBatchDeleteUserByIds(ids);
    }

    @ApiOperation("获取政治面貌")
    @GetMapping("/getOldsterStatus")
    public Result getOldsterStatus(){
        List<OldsterStatusVO> oldsterStatusVO= oldsterService.getOldsterStatus();
        return Result.success(oldsterStatusVO);
    }
}

